<script setup lang="ts">
import { computed, PropType, ref } from "vue";
import laptopIcon from "@/assets/svg/laptop.svg?component";
import More2Fill from "@iconify-icons/ri/more-2-fill";
import { LabPlatformVO } from "@/api/LabPlatformApi";
import router from "@/router";
import PltOptionDialog from "./PltOptionDialog.vue";

defineOptions({
  name: "ReCard"
});

const props = defineProps({
  labPlatform: {
    type: Object as PropType<LabPlatformVO>
  },
  isRuning: {
    type: Boolean
  }
});

const dropdownRef = ref(null);

const emit = defineEmits(["manage-product", "delete-item"]);

const formDialogVisible = ref(false);

const handleClickOption = (product: LabPlatformVO) => {
  formDialogVisible.value = true;
};

const handleClickManage = (product: LabPlatformVO) => {
  emit("manage-product", product);
};

const handleClickDelete = async (product: LabPlatformVO) => {
  emit("delete-item", product);
};

const cardClass = computed(() => [
  "list-card-item",
  { "list-card-item__disabled": !props.labPlatform.isDefault }
]);

const cardLogoClass = computed(() => [
  "list-card-item_detail--logo"
  // { "list-card-item_detail--logo__disabled": !props.labPlatform.isDefault }
]);

const routerTo = (tempname, tempquery) => {
  router.push({
    name: tempname,
    query: tempquery
  });
};
</script>

<template>
  <div :class="cardClass">
    <div class="list-card-item_detail bg-bg_color">
      <el-row justify="space-between">
        <el-row>
          <div style="display: flex; justify-content: space-between">
            <div :class="cardLogoClass">
              <laptopIcon />
            </div>
            <div>
              <el-text
                truncated
                style="
                  margin-left: 16px;
                  white-space: nowrap;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  width: 130px;
                "
                size="large"
              >
                {{ labPlatform.name }}
              </el-text>
            </div>
          </div>
        </el-row>
        <el-row style="margin-left: auto">
          <div>
            <el-dropdown trigger="click" ref="dropdownRef">
              <IconifyIconOffline :icon="More2Fill" class="text-[24px]" />
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item
                    @click="
                      routerTo('Expconfig', {
                        name: labPlatform.name,
                        id: labPlatform.id
                      })
                    "
                  >
                    实验配置
                  </el-dropdown-item>
                  <el-dropdown-item
                    :disabled="isRuning"
                    @click="handleClickManage(labPlatform)"
                  >
                    管理
                  </el-dropdown-item>
                  <el-dropdown-item
                    :disabled="isRuning"
                    @click="handleClickDelete(labPlatform)"
                  >
                    删除
                  </el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-row>
      </el-row>

      <p class="list-card-item_detail--content text-text_color_regular">
        {{ labPlatform.desc }}
      </p>
      <el-row justify="space-between">
        <div class="list-card-item_detail--desc text-text_color_regular">
          {{ labPlatform.name }}
        </div>
      </el-row>

      <el-row>
        <div class="list-card-item_detail--desc text-text_color_regular">
          {{ labPlatform.updateTime }}
        </div>
      </el-row>
    </div>
  </div>
  <PltOptionDialog v-model:visible="formDialogVisible" :data="labPlatform" />
</template>

<style scoped lang="scss">
.list-card-item {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
  overflow: hidden;
  cursor: pointer;
  border-right: var(--el-card-border-color) solid 1px;
  border-bottom: var(--el-card-border-color) solid 1px;

  &_detail {
    flex: 1;
    min-height: 140px;
    padding: 24px 32px;

    &--logo {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 24px;
      height: 24px;
      font-size: 32px;
      color: #0052d9;
      background: #e0ebff;
      border-radius: 50%;

      &__disabled {
        color: #a1c4ff;
      }
    }

    &--operation {
      display: flex;
      height: 100%;

      &--tag {
        border: 0;
      }
    }

    &--name {
      margin: 24px 0 8px;
      font-size: 16px;
      font-weight: 400;
    }

    &--content {
      display: -webkit-box;
      min-height: 40px;
      margin-top: 12px;
      margin-bottom: 12px;
      overflow: hidden;
      font-size: 14px;
      line-height: 20px;
      text-overflow: ellipsis;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }

    &--desc {
      display: -webkit-box;
      overflow: hidden;
      font-size: 12px;
      line-height: 20px;
      text-overflow: ellipsis;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }

  &__disabled {
    .list-card-item_detail--name {
      color: var(--el-text-color-regular);
    }
    .list-card-item_detail--desc {
      color: var(--el-text-color-regular);
    }

    .list-card-item_detail--operation--tag {
      color: #bababa;
    }
  }
}
</style>
